package container

import (
	"github.com/docker/go-connections/nat"
	"time"

	"xemo.top/docker/docker/api/types/strslice"
)

// MinimumDuration为用户配置的持续时间设定了最小值。
// MinimumDuration puts a minimum on user configured duration.
// 这是为了防止API在时间单位上出错。例如，API可能将3设置为healthCheck间隔，意图为3秒，但Docker将其解释为3纳秒。
// This is to prevent API error on time unit.For example,API may set 3 as healthCheck interval with intention of 3 seconds,but Docker interprets it as 3 nanoseconds.
const MinimumDuration = 1 * time.Millisecond

// HealthConfig保存HEALTHCHECK功能的配置设置。
// HealthConfig holds configuration settings for the HEALTHCHECK feature
type HealthConfig struct {
	// 测试是检查容器是否健康的测试。
	// Test is the test to perform to check that the container is healthy.
	// An empty slice means to inherit the default
	// The options are:
	// {} : inherit healthCheck
	// {"NONE"} : disable  healthCheck
	// {"CMD",args...} : exec arguments directly
	// {"CMD-SHELL",command} : run command with system's default shell
	Test []string `json:",omitempty"`

	//零表示继承。持续时间表示为整数纳秒。
	// Zero means to inherit. Durations are expressed as integer nanoseconds.

	//间隔是检查之间等待的时间。
	// Interval is the time to wait between checks.
	Interval time.Duration `json:",omitempty"`
	//超时是指在认为支票已挂起之前等待的时间。
	// Timeout is the time to wait before considering the check to have hung.
	Timeout time.Duration `json:",omitempty"`
	//在重试开始倒计时之前，容器初始化的开始时间段。
	// The start period for the container to initialize before the retries starts to count down.
	//Retries是将容器视为不健康所需的连续失败次数。
	// Retries is the number of consecutive failures needed to consider a container as unhealthy.
	// Zero means inherit.
	Retries int `json:",omitempty"`
}

// Config 包含有关容器的配置数据。
// Config contains the configuration data about a container.
// 它应该只保存有关容器的便携式信息。
// It should hold only portable information about the container.
// 在这里，“可移植”意味着“独立于我们运行的主机”。
// Here, "portable" means "independent from the host we are running on".
// 不可移植信息*应该*出现在HostConfig中。
// Non-portable information *should* appear in HostConfig.
// 添加到此结构中的所有字段都必须标记为“omitempty”，以保持从旧的“v1Compatibility”配置中获得可预测的哈希值。
// All fields added to this struct must be marked `omitempty` to keep getting predictable hashes from the old `v1Compatibility` configuration.
type Config struct {
	Hostname   string // Hostname
	Domainname string // Domainname
	// 将在容器内运行命令的用户也支持User:group
	// User that will run the command(s) inside the container, also support user:group
	User string
	//附加标准输入，实现用户交互
	// Attach the standard input,makes possible user interaction
	AttachStdin bool
	// Attach the standard output
	AttachStdout bool
	// Attach the standard error
	AttachStderr bool
	// 暴露端口列表
	// List of exposed ports
	ExposedPorts nat.PortSet `json:",omitempty"`
	//将标准流附加到tty，包括未关闭的stdin。
	// Attach standard streams to a tty,including stdin if it is not closed.
	Tty bool
	// Open stdin
	OpenStdin bool
	//如果为true，请在1个连接的客户端断开连接后关闭stdin。
	// If true,close stdin after the 1 attached client disconnects.
	StdinOnce bool
	//要在容器中设置的环境变量列表
	// List of environment variable to set in the container
	Env []string
	//启动容器时运行的命令
	// Command to run when starting the container
	Cmd strslice.StrSlice
	//HealthCheck描述了如何检查容器是否健康
	// HealthCheck describes how to check the container is healthy
	HealthCheck *HealthConfig `json:",omitempty"`
	// 如果命令已经转义 (意味着视为命令行)(Windows特定)，则为True。
	// True if command is already escaped (meaning treat as a command line)(Windows specific).
	ArgsEscaped bool
	// 操作员传递的图像名称 (例如，可以是符号)
	// Name of the image as it was passed by the operator (e.g. could be symbolic)
	Image string
	// 用于容器的卷 (装入) 列表
	// List of volumes (mounts) used for the container
	Volumes map[string]struct{}
	// 将启动命令中的当前目录 (PWD)
	// Current directory (PWD) in the command will be launched
	WorkingDir string
	// 启动容器时运行的entrypoint
	// Entrypoint to run when starting the container
	Entrypoint strslice.StrSlice
	// Is network disabled
	NetworkDisabled bool `json:",omitempty"`
	// Mac Address of the container
	MacAddress string `json:",omitempty"`
	// 在映像Dockerfile上定义的ONBUILD元数据
	// ONBUILD metadata that were defined on the image Dockerfile
	OnBuild []string
	// 设置到此容器的标签列表
	// List of labels set to this container
	Labels map[string]string
	// Signal to stop a container
	StopSignal string `json:",omitempty"`
	// Timeout (in seconds) to stop a container
	StopTimeout *int `json:",omitempty"`
	// Shell for shell-form of RUN,CMD,ENTRYPOINT
	Shell strslice.StrSlice
}
